<template>
  <div class="wrap">
    <div class="deleStatus" @click="showmsg = true">
      系统消息
      <img src="@/assets/deleMsg.png" alt="" class="deleImg" />
    </div>
    <div style="height: 5px; width: 100%; background-color: #fff"></div>
    <div v-if="resSysMessageList.length>0">
      <div
        class="msgItem"
        @click="jumpSystemInfo(item.id)"
        v-for="(item, index) in resSysMessageList"
        :key="index"
      >
        <div class="date">{{ item.createTime }}</div>
        <div class="whiteWap">
          <div class="msgTitle">{{ item.messageTitle }}</div>
          <div class="more">
            查看更多
            <img src="@/assets/rightGreyArrow.png" alt="" class="rightGreyArrow" />
          </div>
        </div>
      </div>
    </div>
    <div class="msgItem" style="font-size: 12px; color: #181818; margin-left: 15px; margin-top: 20px" v-else>
      暂无消息...
    </div>
    <!-- 遮罩层-清空消息： -->
    <div class="maskWrap" v-if="showmsg">
      <div class="maskBg" @click="showmsg = false"></div>
      <div class="chooseNumWrap">
        <div class="optionsItem" @click="getClearMessage(3)">清空消息</div>
        <div class="optionsItem dele" @click="showmsg = false">取消</div>
      </div>
    </div>
  </div>
</template>

<script>
import { Switch } from "vant";
import { apiSysMessageList, apiClearMessage } from "@/request/api"; // api接口
export default {
  name: "App",
  data() {
    return {
      showmsg: false,
      resSysMessageList: "",
    };
  },
  mounted() {
    document.querySelector("body").setAttribute("style", "background-color:#F2F4FA");
    this.getSysMessageList();
  },
  methods: {
    //获取系统消息列表
    getSysMessageList() {
      apiSysMessageList({}).then((res) => {
        this.resSysMessageList = res.data;
        console.log("系统消息列表", this.resSysMessageList);
      });
    },
    //清空消息的操作：
    getClearMessage(i) {
      apiClearMessage({
        msgType: i,
      }).then((res) => {
        if (res.code == 200) {
          this.showmsg = false;
          this.getSysMessageList();
          this.$toast.success("已清空");
        }
      });
    },
    jumpSystemInfo(i) {
      this.$router.push({
        path: "/pages/systemMsgInfo",
        query: {
          //传递参数
          id: i,
        },
      });
    },
  },
  created() {},
  components: {
    [Switch.name]: Switch,
  },
};
</script>

<style scoped>
.deleStatus {
  font-size: 16px;
  font-weight: 500;
  color: #181818;
  text-align: center;
  height: 50px;
  line-height: 50px;
}
.deleImg {
  width: 13px;
  height: 13px;
}
.msgItem {
  margin-top: 20px;
}
.date {
  font-size: 10px;
  font-weight: 300;
  color: #666666;
  text-align: center;
  margin-bottom: 15px;
}
.whiteWap {
  background: #ffffff;
  border-radius: 15px;
  width: calc(90% - 30px);
  margin: 0 auto;
  padding: 15px;
}
.msgTitle {
  font-size: 12px;
  font-weight: 500;
  color: #181818;
  /* padding-bottom: 15px; */
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  /* autoprefixer: off */
  -webkit-box-orient: vertical;
  /* autoprefixer: on */
  -webkit-line-clamp: 2;
}
.more {
  font-size: 10px;
  font-weight: 300;
  color: #666666;
  margin-top: 10px;
  padding-top: 15px;
  border-top: 1px solid #e5e5e5;
}
.rightGreyArrow {
  width: 3px;
  height: 5px;
  padding-left: 5px;
  padding-bottom: 3px;
}
.maskWrap {
}
.maskBg {
  width: 100%;
  min-height: 100vh;
  opacity: 0.35;
  background-color: #000;
  position: fixed;
  top: 0px;
}
.chooseNumWrap {
  width: 100%;
  background-color: #fff;
  position: fixed;
  bottom: 0px;
  border-radius: 20px 20px 0px 0px;
}
.optionsItem {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
  color: #000;
  font-size: 14px;
  text-align: center;
}
</style>
